﻿#ifndef _PROTOCOL_H__
#define _PROTOCOL_H__

#include "dl_net_data.h"
#include "protocol_struct.h"

#define NET_CFG                                     (64)
#define COM_CFG                                     (513)
#define IO_CFG                                      (1024)
//172
#define LAST_CFG                                    (4000)
#define PRG_FILE_CFG                                (4090)
#define AUTH_CODE                                   (4001)

/************************DL_CMD********************************/
#define DL_CMD_VER                       (0x0100)

#define DL_FRM_HEAD                      "~!@#"
#define DL_FRM_TAIL                      "$%\r\n"

#define DL_FRM_HEAD_LEN                  (4)          //帧头长度
#define DL_FRM_PREDAT_LEN                (4)          //指令长度
#define DL_FRM_CRC_LEN                   (2)          //校验长度
#define DL_FRM_TAIL_LEN                  (4)          //帧尾长度

#define DL_FRM_FRONT_LEN                 (DL_FRM_HEAD_LEN + DL_FRM_PREDAT_LEN)   //
#define DL_FRM_BACK_LEN                  (DL_FRM_CRC_LEN + DL_FRM_TAIL_LEN)      //
#define DL_FRM_SIDES_LEN                 (DL_FRM_FRONT_LEN + DL_FRM_BACK_LEN)    //
#define DL_FRM_DATA_IDX                  (6)     // 数据索引
#define DL_FRM_MIN_LEN                   (14)    // 最小数据长度


#define  FRM_NOT_ENOUGH  -1

typedef enum
{
	DL_FRM_RET_IO_ERR = -1,                                                      // 
	DL_FRM_RET_SUCCESS,                                                          //
	DL_FRM_RET_ERROR,                                                            // 
	DL_FRM_RET_PACKET_ERR,                                                       //
}enum_decode_ret;



int decode_dl(dl_protocol_data_t* netdata);
int encode_dl(uint8_t* cmd, int* cmdlen, uint8_t* data, int datalen);

#endif //_PROTOCOL_H__
